home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1061 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.1 KB

  1. Path: cs.mu.OZ.AU!bounce-back
  2. From: ajay@lehman.com (Ajay Kamdar)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: sample auto_ptr template
  5. Date: 12 Apr 96 17:36:33 GMT
  6. Organization: Lehman Brothers, Inc.
  7. Approved: fjh@cs.mu.oz.au
  8. Message-ID: <199604121609.MAA27937@jabba.lehman.com>
  9. References: <009A04DA6A831C40.49800EAC@ittpub.nl> <bill-0804960932250001@bgibbons.vip.best.com> <4kcr2d$p03@jabba.lehman.com> <KANZE.96Apr10111407@gabi.gabi-soft.fr>
  10. NNTP-Posting-Host: mundook.cs.mu.oz.au
  11. X-Original-Date: Fri, 12 Apr 1996 12:09:49 -0400
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMW6UqOEDnX0m9pzZAQEGWgF/U3dI65U3e2aDb19xaMHD4+CoOeEYsFXl
  14.     QCmXSplyE7+s8WTXULXimdRy3vqF9Tjd
  15.     =1fu6
  16. Originator: fjh@mundook.cs.mu.OZ.AU
  17.  
  18. In article <KANZE.96Apr10111407@gabi.gabi-soft.fr>,
  19. J. Kanze <kanze@gabi-soft.fr> wrote:
  20. >In article <4kcr2d$p03@jabba.lehman.com> ajay@lehman.com (Ajay Kamdar)
  21. >writes:
  22. >
  23. >|> You didn't say whether the example I gave was exception
  24. >|> safe or not.
  25. >
  26. >But I did.  It's not.
  27. >
  28. >|> To reiterate the main points of the example
  29. >|>    + The caller directly initializes an auto_ptr with
  30. >|>      the returned value from the calee.
  31. >|>      auto_ptr<X> ptr(get_X());
  32. >
  33. >|>    + The callee releases the pointer from it's own
  34. >|>      auto_ptr in it's return statement.
  35. >
  36. >|> No copy constructors are involved in the return. Hence
  37. >|> there is no possibility of an exception thrown from
  38. >|> a user defined copy constructor. So which window are
  39. >|> you referring to during which there is no exception
  40. >|> safety? I claim there is none.
  41. >
  42. >The destructors of any local variables in get_X.
  43.  
  44. Yes, you are right that the destructors of local variables in
  45. get_X() could propagate exceptions. I missed that in my initial
  46. analysis. However, in a previous article I believe I have shown
  47. clearly that propagating exceptions out of destructors is an
  48. extremely poor practice. Depending upon whether the destruction
  49. of remaining stack variables in get_X() is attempted if one of
  50. the statck variables throws an exception, the program will either
  51. terminate or will likely leak memory. I think it would be a
  52. dubious choice to make auto_ptr less safe to use by making it have
  53. copy semantics to support such off beat no-win cases.
  54.  
  55.  
  56.  
  57.                 [snip]
  58. >
  59. >|> So which one is better for the C++ programmer? An approach
  60. >|> which can lead to disastorous surprises at run-time
  61. >|> (auto_ptr with copy semantics approach) definitely does
  62. >|> not look the right choice under any stretch of imagination.
  63. >
  64. >In short, you are suggesting that memory leaks are OK, as long as they
  65. >don't occur too often.  This isn't the case for my applications.
  66.  
  67.  
  68. Applications which cannot tolerate even occasional memory leaks
  69. when exceptions propagate through destructors (if they are
  70. lucky to live past those exceptions) should go through sufficient
  71. testing to find all such occurences. Enough memory leak detection
  72. tools exist on the market to make this possible. The onus
  73. of finding those leaks is on those applications. Alternatively
  74. they could use garbage collection. Given that even an auto_ptr
  75. having copy semantics does not really solve the problem with
  76. exceptions emnating from destructors, I have a hard time buying
  77. into warping the auto_ptr design and making it unsafe for
  78. everyone to support such applications.
  79.  
  80. Moreover, if the unsafe copy semantics are moved out of auto_ptr
  81. into taligent_ptr, applications which are willing to accept
  82. the unsafe semantics and the lack of a complete solution inspite
  83. of sacrificing safety can always use the taligent_ptr. But it
  84. would be a *choice* that is not imposed upon everyone using the
  85. standard auto_ptr class.
  86.  
  87. --
  88. Ajay Kamdar        |    Email: ajay@lehman.com    |    Standard Disclaimer 
  89. Lehman Brothers    |    Phone: (201) 524-5048     |
  90. ---
  91. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  92. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  93. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  94. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  95. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  96.